<?php
/**
 * Project:
 * File:        Strings.php
 *
 * @link 		http://.../lib
 * @copyright 	2007
 * @author 		ivan <ldmmyx@hotmail.com>
 * @version 	1.0
 * 
 * @ substr_cut($str_cut,$length = 65)
 */
class Strings
{
	function Strings()
	{
	}

	public function getCharNum($text)
	{
		$text	= trim($text);
//		$text 	= str_replace($text, '%', 'percent');
//		$text 	= str_replace($text, '%', 'percent');
		
		$return = '';
		$len 	= strlen($text);
		for($i = 0; $i < $len; $i++){
			$ch = ord($text[$i]);
			if($ch > 47 && $ch < 58 || $ch > 64 && $ch < 91 || $ch > 96 && $ch < 123)
				$return .= $text[$i];
			else{
				$return .= '-';
			}
		}
		
		$return	= $this->deleteSpaces($return, '--', '-');
		
		return trim($return, '-');
	}
	
	public function deleteSpaces($text, $search, $replace)
	{
		$pos = strrpos($text, $search);
		
		if ($pos === false) { // note: three equal signs
		    return $text;
		}else{
			while(true){
				$pos = strrpos($text, $search);
				if ($pos === false) { // note: three equal signs
					break;
				}else{
					$text = str_replace($search, $replace, $text);					
				}
			}
		}

		return $text;
	}
	
	public static function getCutValue($startFlag, $endFlag, $content)
	{
		$value 	= '';
		
		$lowerContent = strtolower($content);
		$pos1 = strpos($lowerContent, $startFlag);
	
	    if( $pos1 !== false ) {
	    	$startLen = strlen($startFlag);
	    	
	    	$pos2 = strpos($lowerContent, $endFlag, $pos1 + $startLen);
	    	if( $pos2 !== false ) {
	   			$value = substr($content, $pos1 + $startLen, $pos2 - $pos1 - $startLen);
	    	}
	    }
	
		return $value;
	}

	public static function getStartValue($endFlag, $content)
	{
		$value 	= '';
		
		$lowerContent = strtolower($content);
		$pos1 = strpos($lowerContent, $endFlag);
	
	    if( $pos1 !== false ) {
	   		$value = substr($content, 0, $pos1);
 	    }
	
		return $value;
	}
		
}
?>
